<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
</head>
<style>
  .item {
    line-height: 100px;
  }
</style>

<body>
  <div id="app">
    <!-- 上拉一次，加入一条随机数据 
      van-list
         v-model="loading"   loading:是否处于加载中，当滚动条距离离底部小于300时自动触发load就去，loading=true
         finished:boolean:true:加载完成 false:没完成
         finished-text:加载完成后显示的文本
         @load="调用加载的方法"   
         
         
     van-pull-refresh
         v-model:loading:是否处于下拉刷新中
         @refresh:刷新，重新调用接口
         refresh需要做的事件：
            1:还原上拉加载的属性
            2：调用刷新接口
            3：将isLoading=false
            4：静默刷新上拉加载组件
      
      -->
    <van-pull-refresh v-model="isloading" @refresh="refresh">
      <van-list v-if="bol" v-model="loading" :finished="finished" finished-text="没有更多了" @load="load">
        <div class="item" v-for="(item, index) in arr" :key="index">
          {{item}}
        </div>
      </van-list>
    </van-pull-refresh>
  </div>
  <script src="./vue.js"></script>
  <!-- 引入样式文件 -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@2.12/lib/index.css" />


  <script src="https://cdn.jsdelivr.net/npm/vant@2.12/lib/vant.min.js"></script>
  <script>
    new Vue({
      el: '#app',
      data: {
        isloading: false,
        loading: false,
        finished: false,
        bol: true,
        arr: [1, 2, 3, 4, 5]
      },
      methods: {
        load() {
          setTimeout(() => {
            this.arr.push(Date.now())
            // 加载完成将loading=false
            this.loading = false
            // 判断是否加载完成
            if (this.arr.length >= 8) {
              this.finished = true
            }
          }, 2000)
        },
        refresh() {
          // 让上拉加载组件的参数回到初始值
          this.loading = false
          this.finished = false
          setTimeout(() => {
            this.arr = [1, 2]
            // 刷新完成
            this.isloading = false


            // 静默刷新还原组件
            this.bol = false
            this.$nextTick(() => {
              this.bol = true
            })
          }, 3000)
        }
      }
    })
  </script>
</body>

</html>